package com.ellecity06.cwhiskymall.helper

import android.app.Activity
import com.ellecity06.common.utils.ToastUtils
import com.ellecity06.common.utils.logD
import com.ellecity06.cwhiskymall.bean.web.WechatPayReq
import com.tencent.mm.opensdk.modelpay.PayReq
import com.unionpay.UPPayAssistEx

/**
 * @author ellecity06
 * @time 2024/12/16 10:26
 * @des
 */
class PayHelper {
    companion object {
        @JvmStatic
        fun wechatPay(webPayReq: WechatPayReq) {
            if (!wxApi.isWXAppInstalled) {
                ToastUtils.show("请先安装微信！")
                return
            }
            val payReq = PayReq()
            payReq.appId = webPayReq.appid
            payReq.partnerId = webPayReq.partnerid
            payReq.prepayId = webPayReq.prepayid
            payReq.packageValue = webPayReq.packageValue
            payReq.nonceStr = webPayReq.noncestr
            payReq.timeStamp = webPayReq.timestamp
            payReq.sign = webPayReq.sign
            wxApi.sendReq(payReq)
        }
        /**
         * 云闪付支付 ，
         * @param tn 交易流水号
         * @param mode 交易模式 mMode参数解释： "00" - 启动银联正式环境 "01" - 连接银联测试环境
         */
        @JvmStatic
        fun uniPay(activity: Activity, tn: String, mode: String = "00") {
            try {
                logD("tn=$tn")
                UPPayAssistEx.startPay(activity, null, null, tn, mode)
            } catch (e: Exception) {
                ToastUtils.show( "支付失败")
            }

        }
    }
}